//--------------------------------------- NOTES ------------------------------------------------------//
* This table is Table 9 in the paper 
//--------------------------------------------------------------------------------------------------------//

cd  "/YOUR_LOCAL_DIRECTORY" //setting the working directory
clear all //remove all data, labels, matrices etc (incl. Mata functions)
use December8ChanRoth, clear

* Create the key treatment variable
gen byte status_quo = treatment=="status_quo"
la var status_quo  "Status Quo"

* Create Y variable
****** How many balls are used?
gen ballsused = 0
replace ballsused = 1 if player2action=="MixWithLowBlue"
replace ballsused = 1 if player2action=="MixWithHighBlue"
replace ballsused = 2 if player2action=="MixWithBothBlue"

****** Transplant number calculation
gen byte transplanted = player2action=="MixWithLowBlue" | player2action=="MixWithHighBlue" | player2action=="MixWithBothBlue"
replace transplanted=2 if player2action=="MixWithBothBlue"

** Transplant rate
gen transplant_rate = transplanted/2

* Did the TC made the patient worse? - a jar that is worse than an urn is mixed into urn
gen byte madeworse = player1bluecount<player2lowbluecount & player2action=="MixWithLowBlue" 
replace madeworse =1 if player1bluecount<player2highbluecount & player2action=="MixWithHighBlue"
replace madeworse =2 if player1bluecount<player2lowbluecount & player1bluecount<player2highbluecount & player2action=="MixWithBothBlue"
replace madeworse =. if player1action!="Offer" 
replace madeworse =. if player2action=="RejectOffer" 

** make worse rate
gen makeworse_rate = madeworse/transplanted

* Make table

eststo clear

eststo: quietly reg transplant_rate status_quo,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg transplant_rate status_quo player1bluecount,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg transplant_rate status_quo player1bluecount player2highbluecount player2lowbluecount,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

eststo: quietly reg makeworse_rate status_quo,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg makeworse_rate status_quo player1bluecount,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg makeworse_rate status_quo player1bluecount player2highbluecount player2lowbluecount,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

esttab using table_transplants_final0_alt.tex, se r2  keep(status_quo player1bluecount player2highbluecount player2lowbluecount _cons) star(+ 0.1 * 0.05 ** 0.01)

** Change the labels for table
label variable player1bluecount "Jar \# Blue Balls"
label variable player2highbluecount "High Urn \# Blue Balls"
label variable player2lowbluecount "Low Urn \# Blue Balls"

local numbers "& (1) & (2) & (3) & (4) & (5) & (6) \\ \hline"

esttab using table_transplants_final_alt.tex, se r2  keep(status_quo player1bluecount player2highbluecount player2lowbluecount _cons) star(+ 0.1 * 0.05 ** 0.01) b(3) mgroups("Mixing (Transplant) Rate" "\% Mixings Made Urn Worse", pattern(1 0 1 0) prefix(\multicolumn{3}{c}{) suffix(}) span) mlabels(none) nonumbers posthead("`numbers'") label title("Impact on Mixing (“Transplant”) Rate, and Mixings that Gave an Urn Worse Odds for Blue from Alternative Sample") substitute([htbp] [!htbp] \begin{tabular} \small\begin{tabular} {l} {p{\linewidth}}) addnotes("(Robust, clustered by player-pairings)") stat(N r2, label("N" "\[R^2\]") fmt(a3 %9.3fc))
